package LinkedList;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Stack;

public class Test {
    public static void main2(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0);
        arrayList.add(1);
        arrayList.add(2);
        //底层是双向列表
        LinkedList<Integer> list=new LinkedList<>(arrayList);
        System.out.println(list);
           list.add(10);
        System.out.println("========");
           for (Integer x:list){
               System.out.print(x+" ");
           }
        System.out.println("=======");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println("=========");
        ListIterator<Integer> it=list.listIterator() ;
        while(it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println(" =========");
        ListIterator<Integer> it2=list.listIterator(list.size()) ;
        while (it2.hasPrevious()){
            System.out.print(it2.previous()+" ");
        }
        System.out.println(":=======迭代器逆序打印");
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(12);
        stack.push(23);
        stack.push(34);
        stack.push(45);
        System.out.println(stack.size());
        int val=stack.peek();//获取栈顶元素不删除
        System.out.println(val);
        int val2=stack.pop();
        System.out.println(val2);
        int val3=stack.peek();//获取栈顶元素并删除
        System.out.println(val3);
        stack.pop();
        stack.pop();
        stack.pop();
        System.out.println(stack.size());
        boolean ret=stack.empty();//判断栈是否为空
        System.out.println(ret);
    }
}
